package com.zd.controller;/**
 * @Description: OtherdeliveryController
 * @Author:pioneer
 * @Date: 2021-07-23
 * @Version:v1.0
 */

import com.zd.service.lnter.DeliveryServicelnter;
import com.zd.service.lnter.OtherdeliveryServicelnter;
import com.zd.service.lnter.SubstationServicelnter;
import com.zzg.entity.Delivery;
import com.zzg.entity.Otherdelivery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: OtherdeliveryController 外包派送控制器
 * @Author:pioneer
 * @Date: 2021-07-23
 * @Version:v1.0
 */
@Controller
public class OtherdeliveryController {
    @Autowired
    private OtherdeliveryServicelnter otherdeliveryServicelnter;
    @Autowired
    private DeliveryServicelnter deliveryServicelnter;
    @Autowired
    private SubstationServicelnter substationServicelnter;

    /**
     * 查询外包派送列表相关的所有信息
     * @param page 页码
     * @param limit 条目数
     * @return map
     */
    @RequestMapping("queryOtherdeliverylist")
    @ResponseBody
    public Map<String,Object> queryOtherdeliverylist(int page, int limit){
        System.out.println ("queryOtherdeliverylist进：page"+page+"\tlimit"+limit);
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",otherdeliveryServicelnter.selectOtherdeliverylist ().size ());
        map.put("data",otherdeliveryServicelnter.pagingqueryOtherdeliverylist(page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 车辆牌号查询给下拉框赋值
     * @return
     */
    @RequestMapping("selectOtherdeliverylist")
    @ResponseBody
    public List<Otherdelivery> selectOtherdeliverylist(){
        List<Otherdelivery> otherdeliveryList= otherdeliveryServicelnter.selectOtherdeliverylist ();
        System.out.println ("selectOtherdeliverylist:"+otherdeliveryList);
        return otherdeliveryList;
    }

    /**
     * 多条件查询外包派送列表所有信息
     * @return map集合
     */
    @RequestMapping("conditionqueryOtherdeliverylist")
    @ResponseBody
    public Map<String,Object> conditionqueryOtherdeliverylist(Otherdelivery otherdelivery){
        int page=1;
        int limit=10;
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",otherdeliveryServicelnter.getOtherdeliverylistwhere (otherdelivery));
        map.put("data",otherdeliveryServicelnter.conditionqueryOtherdeliverylist (otherdelivery,page,limit));
        System.out.println (map);
        return map;
    }
    @RequestMapping("getOtherdeliveryByid")
    @ResponseBody
    public Otherdelivery getOtherdeliveryByid(String deliverynumber){
        Otherdelivery otherdelivery=otherdeliveryServicelnter.getOtherdeliveryByid (deliverynumber);
        return otherdelivery;
    }

    @RequestMapping("updateOtherdelivery")
    public void updateOtherdelivery(Otherdelivery otherdelivery, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int ser=deliveryServicelnter.getupdateDelivery (otherdelivery.getDeliverynumber(),otherdelivery.getDeliveryDate (),otherdelivery.getDeliveryfee (),otherdelivery.getOperator ());
        Delivery delivery=deliveryServicelnter.getDeliveryByid (otherdelivery.getDeliverynumber());
        System.out.println ("分站："+otherdelivery.getArrivesubstation ()+"分站id"+delivery.getSubstation());
        int sre=substationServicelnter.updateSubstation (otherdelivery.getArrivesubstation (),delivery.getSubstation());
        if(ser>=0){
            out.write("修改成功");
        }else{
            out.write("修改失败");
        }
    }
}
